package com.labichaoka.chaoka.ui.home.fragment.my.set.info;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.labichaoka.chaoka.R;
import com.labichaoka.chaoka.base.BaseActivity;
import com.labichaoka.chaoka.entity.PersonInfoResponse;
import com.labichaoka.chaoka.utils.MyScrollView;
import com.labichaoka.chaoka.utils.ToastUtils;

import java.util.List;

import butterknife.BindView;

public class PersonInfoDisplayActivity extends BaseActivity implements PersonInfoDisplayView {
    @BindView(R.id.uniRec_msg)
    TextView uniRecMsg;
    @BindView(R.id.graduateDate)
    TextView graduateDate;
    @BindView(R.id.uniName)
    TextView uniName;
    @BindView(R.id.hasWork)
    TextView hasWork;
    @BindView(R.id.company)
    TextView company;
    @BindView(R.id.expectAmount)
    TextView expectAmount;
    @BindView(R.id.cName1)
    TextView cName1;
    @BindView(R.id.cPhone1)
    TextView cPhone1;
    @BindView(R.id.cRelation_msg1)
    TextView cRelationMsg1;
    @BindView(R.id.cName2)
    TextView cName2;
    @BindView(R.id.cPhone2)
    TextView cPhone2;
    @BindView(R.id.cRelation_msg2)
    TextView cRelationMsg2;

    @BindView(R.id.home_address)
    TextView homeAddress;
    @BindView(R.id.home_address_detail)
    TextView homeAddressDetail;

    @BindView(R.id.industry)
    TextView industry;
    @BindView(R.id.job)
    TextView job;
    @BindView(R.id.merry)
    TextView merry;
    @BindView(R.id.email)
    TextView email;


    @BindView(R.id.info)
    MyScrollView info;
    @BindView(R.id.work_container)
    LinearLayout workContainer;

    @BindView(R.id.empty_layout)
    RelativeLayout emptyLayout;

    private PersonInfoDisplayPresenter presenter;

    @Override
    protected int initLayoutId() {
        return R.layout.activity_person_info_display;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        presenter = new PersonInfoDisplayPresenterImpl(this, new PersonInfoDisplayInteractorImpl());
        presenter.getPersonInfo();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void showProgress() {
        showLoadingProgress();
    }

    @Override
    public void hideProgress() {
        hideLoadingProgress();
    }

    @Override
    public void showMessage(String str) {
        ToastUtils.show(str);
    }

    @Override
    public void setUI(PersonInfoResponse response) {
        if (response.getData().getWorkInfo() == null) {
            info.setVisibility(View.GONE);
            emptyLayout.setVisibility(View.VISIBLE);
            return;
        }

        String uniRec=response.getData().getEducationalInfo().getUniRec_msg();

        if (TextUtils.isEmpty(uniRec)){
            uniRecMsg.setText("-");
        }else{
            uniRecMsg.setText(uniRec);
        }

        String graduate=response.getData().getEducationalInfo().getGraduateDate();

        if (TextUtils.isEmpty(graduate)){
            graduateDate.setText("-");
        }else{
            graduateDate.setText(graduate);
        }

        String uni_name=response.getData().getEducationalInfo().getUniName();

        if(TextUtils.isEmpty(uni_name)){
            uniName.setText("-");
        }else{
            uniName.setText(uni_name);
        }

        String workStr = response.getData().getWorkInfo().getHasWork();
        if (!TextUtils.isEmpty(workStr) && workStr.equals("0")) {
            //没有工作
            hasWork.setText(response.getData().getWorkInfo().getHasWork_msg());
            company.setText("-");
        }else{
            hasWork.setText(response.getData().getWorkInfo().getHasWork_msg());
            company.setText(response.getData().getWorkInfo().getCompany());
        }
        expectAmount.setText(response.getData().getExpectAmount());
        List<PersonInfoResponse.DataBean.ContactArrBean> list = response.getData().getContactArr();
        if (list != null && list.size() == 1) {
            cName1.setText(list.get(0).getCName());
            cPhone1.setText(list.get(0).getCPhone());
            cRelationMsg1.setText(list.get(0).getCRelation_msg());
        } else if (list != null && list.size() >= 2) {
            cName1.setText(list.get(0).getCName());
            cPhone1.setText(list.get(0).getCPhone());
            cRelationMsg1.setText(list.get(0).getCRelation_msg());
            cName2.setText(list.get(1).getCName());
            cPhone2.setText(list.get(1).getCPhone());
            cRelationMsg2.setText(list.get(1).getCRelation_msg());
        }

        homeAddress.setText(response.getData().getProvinceCityDistrict());
        homeAddressDetail.setText(response.getData().getLiveAddrDetailInfo());

        industry.setText(response.getData().getIndustry());
        job.setText(response.getData().getOccupation());
        merry.setText(response.getData().getMarriage());
        email.setText(response.getData().getEmail());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.onDestroy();
    }
}
